package com.brillilab.service.core.method.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.common.entity.PageVo;
import com.brillilab.dao.mapper.method.MethodShareMapper;
import com.brillilab.domain.enums.method.MethodDealStateEnum;
import com.brillilab.domain.enums.method.RecommendAuditStateEnum;
import com.brillilab.domain.po.method.MethodRecommendAudit;
import com.brillilab.domain.po.method.MethodShare;
import com.brillilab.domain.vo.inventory.ReagentInventoryWithOwner;
import com.brillilab.service.core.method.IMethodShareService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wuzhiyu
 * @Title: MethodShareServiceImpl
 * @ProjectName brill_lab
 * @Description: TODO
 * @date 2019/2/2313:59
 */
@Service
@Transactional
public class MethodShareServiceImpl implements IMethodShareService {
    @Resource
    private MethodShareMapper methodShareMapper;

    @Override
    public boolean addList(List<MethodShare> shareList) {
        return methodShareMapper.insertList(shareList) > 0;
    }

    @Override
    public MethodShare getByIdAndReceiveMemberId(Long shareId, Long labMemberId) {
        LambdaQueryWrapper<MethodShare> query = new LambdaQueryWrapper<>();
        query.eq(MethodShare::getId, shareId);
        query.eq(MethodShare::getReceiveMemberId, labMemberId);
        return methodShareMapper.selectOne(query);
    }

    @Override
    public boolean updateById(MethodShare share) {
        return methodShareMapper.updateById(share) > 0;
    }

    @Override
    public PageVo<MethodShare> listSharePaged(Long labMemberId, Integer state,Integer pageIndex, Integer rows, boolean isShareToMe, boolean isDesc) {
        PageHelper.startPage(pageIndex, rows);
        List<MethodShare> shareList = methodShareMapper.listSharePaged(labMemberId, state, isShareToMe, isDesc);
        return new PageVo<MethodShare>(shareList);
    }

	@Override
	public int countUntreated(Long labMemberId) {
		LambdaQueryWrapper<MethodShare> query = new LambdaQueryWrapper<>();
		query.eq(MethodShare::getReceiveMemberId, labMemberId);
		query.eq(MethodShare::getState, 0);
		return methodShareMapper.selectCount(query);
	}

    @Override
    public boolean deleteNotDeal(Long methodId) {
        LambdaQueryWrapper<MethodShare> query = new LambdaQueryWrapper<>();
        query.eq(MethodShare::getMethodId,methodId);
        query.eq(MethodShare::getState, MethodDealStateEnum.WaiteDeal.getState());
        return methodShareMapper.delete(query)>0;
    }
}
